home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / TextEdit / TextEditObject.h < prev    next >
Text File  |  2000-06-23  |  6KB  |  172 lines

  1. // TextEditObject.h
  2.  
  3. #ifndef TextEditObject_h
  4. #define TextEditObject_h
  5.  
  6. #ifndef TextEditUser_h
  7. #include "TextEditUser.h"
  8. #endif
  9. #ifndef ConstData_h
  10. #include "ConstData.h"
  11. #endif
  12. #ifndef Rectangle_h
  13. #include "Rectangle.h"
  14. #endif
  15. #ifndef Face_h
  16. #include "Face.h"
  17. #endif
  18. #ifndef SourceMode_h
  19. #include "SourceMode.h"
  20. #endif
  21. #ifndef GrafPortObject_h
  22. #include "GrafPortObject.h"
  23. #endif
  24. #ifndef TextEditCutter_h
  25. #include "TextEditCutter.h"
  26. #endif
  27. #ifndef TextEditPaster_h
  28. #include "TextEditPaster.h"
  29. #endif
  30. #ifndef Overflow_h
  31. #include "Overflow.h"
  32. #endif
  33.  
  34. class TextEditObject: public TextEditUser
  35.   {
  36.     private:
  37.         TEHandle te;
  38.     
  39.         // not implemented:
  40.             TextEditObject( const TextEditObject& );
  41.             void operator=( const TextEditObject& );
  42.         
  43.         TERec& Record()                                    { return **te; }
  44.         const TERec& Record() const                    { return **te; }
  45.         
  46.         Rectangle& Destination()                        { return static_cast<Rectangle&>( Record().destRect ); }
  47.         const Rectangle& Destination() const        { return static_cast<const Rectangle&>( Record().destRect ); }
  48.         
  49.         Rectangle& View()                                    { return static_cast<Rectangle&>( Record().viewRect ); }
  50.         const Rectangle& View() const                    { return static_cast<const Rectangle&>( Record().viewRect ); }
  51.         
  52.     public:
  53.         TextEditObject( GrafPortObject&,
  54.                              const Rect& screenArea,
  55.                              uint16 wrapWidth );
  56.         
  57.         ~TextEditObject()                                    { TEDispose( te ); }
  58.         
  59.         TEHandle TextEditHandle()                        { return te; }
  60.         
  61.         uint32 WrapWidth() const                        { return Destination().Width(); }
  62.         void SetWrapWidth( uint16 );
  63.         
  64.         Rectangle ScreenArea() const                    { return View(); }
  65.         void SetScreenArea( const Rectangle& );
  66.         
  67.         void DisplayAt( GrafPortObject&,
  68.                              Rectangle area,
  69.                              PointObject scroll );
  70.         
  71.         uint16 Length() const                            { return Asuint16( Record().teLength ); }
  72.         uint16 LineCount() const                        { return Asuint16( Record().nLines ); }
  73.         uint16 LineHeight() const                        { return Asuint16( Record().lineHeight ); }
  74.         const uint16 *LineStarts() const                { return reinterpret_cast<const uint16 *>( Record().lineStarts ); }
  75.         
  76.         bool Active() const                                { return Record().active != 0; }
  77.         void Activate()                                    { TEActivate( te ); }
  78.         void Deactivate()                                    { TEDeactivate( te ); }
  79.         
  80.         void Type( uint8 key );
  81.         
  82.         enum SpecialKey
  83.           {
  84.             backspace = 0x08,
  85.             returnKey = 0x0d,
  86.             leftArrow = 0x1c,
  87.             rightArrow = 0x1d,
  88.             upArrow = 0x1e,
  89.             downArrow = 0x1f
  90.           };
  91.         
  92.         void DeleteBackward()                            { TEKey( backspace, te ); }
  93.         void DeleteForward();
  94.         
  95.         void TypeReturn()                                    { Type( returnKey ); }
  96.         
  97.         void LeftArrow()                                    { TEKey( leftArrow, te ); }
  98.         void RightArrow()                                    { TEKey( rightArrow, te ); }
  99.         void UpArrow()                                        { TEKey( upArrow, te ); }
  100.         void DownArrow()                                    { TEKey( downArrow, te ); }
  101.  
  102.         void SetText( ConstData text );
  103.         ConstData Text() const                            { return ConstData( *Record().hText, Length() ); }
  104.         
  105.         void Idle() const                                    { TEIdle( te ); }
  106.         static uint32 IdlePeriod()                        { return GetCaretTime() + 1; }
  107.         
  108.         void Click( PointObject p, bool shift )    { TEClick( p, shift, te ); }
  109.         
  110.         URange16 Selection() const                        { return URange16( Asuint16( Record().selStart ),
  111.                                                                                          Asuint16( Record().selEnd ) ); }
  112.         void SetSelection( URange16 r )                { TESetSelect( r.Start(), r.End(), te ); }
  113.  
  114.         ConstData SelectedText() const                { return ConstData( *Record().hText + Record().selStart,
  115.                                                                                           *Record().hText + Record().selEnd ); }
  116.         
  117.         URange16 DefaultSelection() const            { return URange16( 0, 0 ); }
  118.         URange16 AllSelection() const                    { return URange16( 0, Length() ); }
  119.         
  120.         enum AlignmentType
  121.           {
  122.             standard = teFlushDefault,
  123.             center = teCenter,
  124.             right = teFlushRight,
  125.             left = teFlushLeft
  126.           };
  127.         
  128.         AlignmentType Alignment() const                { return static_cast<AlignmentType>( Record().just ); }
  129.         void SetAlignment( AlignmentType a )        { TESetAlignment( a, te ); }
  130.         
  131.         void Draw( const Rect& visible ) const        { Assert( Port().IsCurrent() ); TEUpdate( &visible, te ); }
  132.         
  133.         void Recalculate()                                { TECalText( te ); }
  134.         
  135.         PointObject Scroll() const;
  136.         void SetScroll( PointObject );
  137.         
  138.         void ScrollAutomatically()                        { TEAutoView( true, te ); }
  139.         void DontScrollAutomatically()                { TEAutoView( false, te ); }
  140.         
  141.         void RevealSelection()                            { TESelView( te ); }
  142.         
  143.         void DeleteSelection()                            { TEDelete( te ); }
  144.         void ReplaceSelection( ConstData );
  145.         
  146.         void Cut()                                            { TextEditCutter().Cut( te ); }
  147.         void Copy()    const                                    { TextEditCutter().Copy( te ); }
  148.         void Paste()                                        { TextEditPaster().Paste( te ); }
  149.         
  150.         static bool CanPaste()                            { return TextEditClipboard::The().Length() > 0; }
  151.         
  152.         FontNumber Font() const                            { return FontNumber( Record().txFont ); }
  153.         void SetFont( FontNumber font )                { Record().txFont = font.Value(); }
  154.         
  155.         FontSize Size() const                            { return FontSize( uint16( Record().txSize ) ); }
  156.         void SetSize( FontSize size )                    { Record().txSize = int16( size.Value() ); }
  157.         
  158.         ::Style Style() const                            { return Record().txFace; }
  159.         void SetStyle( ::Style style )                { Record().txFace = style; }
  160.         
  161.         SourceMode Mode() const                            { return SourceMode( Record().txMode ); }
  162.         void SetMode( SourceMode mode )                { Record().txMode = mode.Value(); }
  163.         
  164.         ::Face Face() const                                { return ::Face( Font(), Size(), Style() ); }
  165.         void SetFace( const ::Face& face );
  166.         
  167.         GrafPortObject& Port() const                    { return static_cast<GrafPortObject&>( *Record().inPort ); }
  168.         void SetPort( GrafPortObject& port )        { Record().inPort = &port; }
  169.   };
  170.  
  171. #endif
  172.